package com.jy.api.service.impl;

import com.jy.api.dao.WebRechargeDao;
import com.jy.api.domain.WebRecharge;
import com.jy.api.service.CommissionService;
import com.jy.api.util.OkHttpUtils;
import com.jy.api.util.SalesUrlUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lihu on 2017/10/21.
 */
@Slf4j
@Service
public class CommissionServiceImpl implements CommissionService {

    @Autowired
    SalesUrlUtil salesUrlUtil;

    @Autowired
    WebRechargeDao webRechargeDao;


    @Override
    @Transactional
    public void commission(WebRecharge webRecharge) throws IOException {
        String url = salesUrlUtil.commissionUrl();
        Map<String, String> map = new HashMap<>();
        map.put("storeId", webRecharge.getStoreId());
        OkHttpUtils.post(url, JSONObject.fromObject(map).toString());
        webRecharge.setSynchro(true);
        webRechargeDao.save(webRecharge);
    }
}
